package vcp.views;

import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JOptionPane;

import client.Message;
import db.parking.beans.Orders;

import vcp.common.AbstractView;
import vcp.common.IView;
import vcp.gui.forms.CheckInWidgetForm;

public class CheckInView  extends AbstractView implements IView,Observer {
    CheckInWidgetForm formWidget;
    
    public CheckInView(){
    	formWidget = new CheckInWidgetForm();
    }
    
	public CheckInWidgetForm getForm() {
		return formWidget;
	}


	@Override
	public void addController(Object obj) {
		formWidget.getCheckinRegularForm().getBtnCheckIn().addActionListener((ActionListener)obj);
		formWidget.getCheckinRegularForm().getBtnCheckIn().setActionCommand("CheckInRegular");
		formWidget.getCheckInSubscriberForm().getBtnCheackIn().addActionListener((ActionListener)obj);
		formWidget.getCheckInSubscriberForm().getBtnCheackIn().setActionCommand("CheckInSubscribed");
	}

	@Override
	public void update(Observable arg0, Object arg1) {
		Message tempMsg = (Message)arg1;  

		switch(tempMsg.getMsg())
		 {
		 	case "CheckInRegular":
				if(tempMsg.isStatus())
				{
					JOptionPane.showMessageDialog(null , "Welcome to our Lot!");
				}	
				else
				{
					JOptionPane.showMessageDialog(null,"Failed Entering Lot " + tempMsg.getStatusMsg(),"DATABASE ERROR",JOptionPane.ERROR_MESSAGE);
				}
				break;
		 	case "CheckInSubscriber":
				if(tempMsg.isStatus())
				{
					JOptionPane.showMessageDialog(null , "Welcome Subscriber to our Lot!");
				}	
				else
				{
					JOptionPane.showMessageDialog(null,"Failed Entering Lot " + tempMsg.getStatusMsg(),"DATABASE ERROR",JOptionPane.ERROR_MESSAGE);
				}
				break;
		 }
	}		
}
	
